namespace FormStateKeeper
{
    using System;
    using System.Web;

    public abstract class BaseHttpModule : IHttpModule
    {
        public void Init(HttpApplication context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            OnInit(context);

            context.BeginRequest += (sender, e) => OnBeginRequest(new HttpContextWrapper(((HttpApplication)sender).Context));
            context.PostMapRequestHandler += (sender, e) => OnPostMapRequestHandler(new HttpContextWrapper(((HttpApplication)sender).Context));
            context.EndRequest += (sender, e) => OnEndRequest(new HttpContextWrapper(((HttpApplication)sender).Context));
        }

        public void Dispose()
        {
        }

        public virtual void OnInit(HttpApplication httpApp)
        {
        }

        public virtual void OnBeginRequest(HttpContextBase context)
        {
        }

        public virtual void OnPostMapRequestHandler(HttpContextBase context)
        {
        }

        public virtual void OnEndRequest(HttpContextBase context)
        {
        }
    }

}